package javaJob.exercise.primary.string;

import java.util.ArrayList;

public class primary15 {
    public static void main(String[] args) {
        String s = "A man, a plan, a canal: Panama";
        String ss = "0P";
        String sss = " ";
        String ssss = "";
        System.out.println(isPalindrome(ssss));
        System.out.println("OO0");
    }

    static boolean isPalindrome(String s) {
        boolean answer=true;
        String ss  = s.toLowerCase();
        System.out.println(ss);
        ArrayList<Character> ss_char_list = new ArrayList<>();
        for (char a:ss.toCharArray()){
            if ((a-'a'<0 | a-'a'>25 | a==' ')&(a<'0' | a>'9')){
                continue;
            }else {
                ss_char_list.add(a);
            }
            System.out.print(a);
        }
        if (ss_char_list.isEmpty()){
            answer=true;
        }else {
            //        char[] s_answer = ss_char_list.toString().toCharArray();//注意此处无法转为数组，转为数组时元素带有空格
            char[] s_answer = new char[ss_char_list.size()];
            for (int i=0;i<ss_char_list.size();i++){
                s_answer[i]=ss_char_list.get(i);
            }

            System.out.println(ss_char_list);
            System.out.println(" ");
            for (int i=0;i<s_answer.length;i++){
                System.out.print(s_answer[i]);
            }
            System.out.println(" ");

            int tag = s_answer.length-1;
            System.out.println(tag);
//        for (char a:ss_char_list){
//            if (!(s_answer[tag]==a)){
//                   answer=false;
//            }
//            if (tag>0){
//                tag--;
//            }
//            System.out.println("answer:"+s_answer[tag]+" tag:"+tag+" list:"+a);
//        }
            for (int i=0;i<ss_char_list.size();i++){
                if (!(s_answer[tag]==ss_char_list.get(i))){
                    answer=false;
                    System.out.println("----------answer:"+s_answer[tag]+" tag:"+tag+" list:"+ss_char_list.get(i));
                }
                if (tag>0){
                    tag--;
                }
                System.out.println("answer:"+s_answer[tag]+" tag:"+tag+" list:"+ss_char_list.get(i));
            }
        }

        System.out.println(ss);
        return answer;
    }
}
